package com.example.module_patrol.ui.detail

import android.widget.ImageView
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.lib_common.base.BaseActivity
import com.example.lib_common.utils.ToastUtils
import com.example.module_patrol.R
import com.example.module_patrol.databinding.ActivityPatrolDetailBinding
import com.example.module_patrol.ui.PatrolViewmodel
import com.example.module_patrol.adapter.CustomTabEntityy
import com.example.module_patrol.adapter.FragmentAdepter
import com.example.module_patrol.ui.detail.fg.PatrolRecardFragment
import com.example.module_patrol.ui.detail.fg.PatrolStandardFragment
import com.example.module_patrol.ui.detail.fg.WorkOrderFragment
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import dagger.hilt.android.AndroidEntryPoint
@Route(path = "/patrol/PatrolDetailActivity")
@AndroidEntryPoint
class PatrolDetailActivity : BaseActivity<PatrolViewmodel,ActivityPatrolDetailBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_patrol_detail
    private lateinit var adepter: FragmentAdepter
    private val list = mutableListOf<Fragment>()
    private var back: ImageView? = null
    private var more: ImageView? = null

    override fun initView() {
        //将碎片加入集合
        list.add(PatrolStandardFragment())
        list.add(PatrolRecardFragment())
        list.add(WorkOrderFragment())

        //实例化碎片适配器
        adepter = FragmentAdepter(this@PatrolDetailActivity,list);
        mBinding.vp?.setAdapter(adepter);


        val arrayList = ArrayList<CustomTabEntity>();
        arrayList.add( CustomTabEntityy("巡检标准"));
        arrayList.add( CustomTabEntityy("巡检记录"))
        arrayList.add( CustomTabEntityy("工单管理"))
        //为什么要用ArrayList集合，因为我们可以点进去看他的原码，需要的类型是ArrayList
        mBinding.tl?.setTabData(arrayList);
        //导航绑定视图滑动切换工具
        mBinding.tl?.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                mBinding.vp?.setCurrentItem(position);
            }

            override fun onTabReselect(position: Int) {

            }

        })
        //视图滑动切换工具绑定导航
        mBinding.vp?.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                mBinding.tl?.setCurrentTab(position)
            }

        })
        /*
        返回键
         */
        back=mBinding.topBar2.findViewById(R.id.back)
        back!!.setOnClickListener {
            finish()
        }
    }

    override fun initData() {

    }

}